package cn.yunhe.actions;

import cn.yunhe.model.District;
import cn.yunhe.model.Street;
import cn.yunhe.service.StreetBiz;
import cn.yunhe.util.BaseActionUtil;
import cn.yunhe.util.ModelDisplayUtil;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.List;

/*spring注解*/
@Controller(value = "streetAction")
@Scope(value = "prototype")
/*struts2注解*/
/*@ParentPackage(value = "struts-default")*/
@ParentPackage(value = "json-default")
public class StreetAction extends BaseActionUtil {

    List<Street>streetList=new ArrayList<>();

    private int sdid;

    /*spring注解*/
    @Autowired
    @Qualifier("streetBiz")
    StreetBiz streetBiz;

    /*struts2注解*/
    @Action(value = "street_searchStreet1",results = {
            @Result(name = "success",location = "/searchStreet.jsp"),
            @Result(name = "error",location = "/fail2SearchStreet.jsp"),
    })
    public String searchStreet(){
        //此处的Street1对应
        //@Entity(name = "Street1")
        //@Table(name = "street")
        List<Street>streetList=streetBiz.searchStreet("from Street1");
        getRequest().setAttribute("streetList1",streetList);

        ModelDisplayUtil.listStreet(streetList);
        return SUCCESS;
    }
    /*struts2注解*/
    @Action(value = "street_searchStreet",results = {
            @Result(name = "success",location = "/searchStreet.jsp"),
            @Result(name = "error",location = "/fail2SearchStreet.jsp"),
            @Result(name = "streetList1",type = "json",params = {"root","streetList"}),
    })
    public String searchStreet1(){
        //此处的Street1对应
        //@Entity(name = "Street1")
        //@Table(name = "street")
        Street street=new Street();
        street.setDistrict(new District(sdid));
        streetList= streetBiz.searchStreet(street);
        //getRequest().setAttribute("streetList1",streetList);
        System.out.println(streetList.size()+"================================================");
        ModelDisplayUtil.listStreet(streetList);
        //return SUCCESS;
        return "streetList1";
    }


    public StreetBiz getStreetBiz() {
        return streetBiz;
    }

    public void setStreetBiz(StreetBiz streetBiz) {
        this.streetBiz = streetBiz;
    }

    public List<Street> getStreetList() {
        return streetList;
    }

    public void setStreetList(List<Street> streetList) {
        this.streetList = streetList;
    }

    public int getSdid() {
        return sdid;
    }

    public void setSdid(int sdid) {
        this.sdid = sdid;
    }
}
